from datetime import datetime

from sqlalchemy import Column, Integer, String, CHAR, DECIMAL

from models.base import Base


class report_info(Base):
    __tablename__ = 'report_info'
    id = Column(Integer, primary_key=True, autoincrement=True)
    order_number = Column(String(80), default='')
    title = Column(String(200), nullable=False)
    author = Column(String(100), default='佚名')
    chars_sum = Column(Integer, default=0)
    create_time = Column(Integer, default=0)
    total_rate = Column(DECIMAL(5, 2), default=0)
    except_author_rate = Column(DECIMAL(5, 2), default=0)
    except_quote_rate = Column(DECIMAL(5, 2), default=0)
    paragraph_count = Column(Integer, default=0)
    sentence_count = Column(Integer, default=0)
    completed = Column(Integer, default=0)
    user = Column(Integer, default=0)

    def __init__(self):
        self.create_time = int(datetime.now().timestamp())

    @property
    def create_datetime(self):
        if self.create_time:
            return datetime.utcfromtimestamp(self.create_time + 28800).strftime("%Y-%m-%d %H:%M:%S")
        else:
            return None
